package www.houdoudou.com.customer;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;
import www.houdoudou.com.common.TelnumVerifyManagement;
import www.houdoudou.com.supplier.SupplierDoSth;
import www.houdoudou.com.supplier.SupplierManagement;

public class CustomerServlet extends HttpServlet{
	private static final long serialVersionUID = 5L;
	
	
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		//super.doGet(req, resp);
		 PrintWriter print=resp.getWriter();  
		 print.println("alessio say hello to you");
		 print.close();
	}



	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		//super.doPost(req, resp);
		 req.setCharacterEncoding("UTF-8"); 
		    resp.setCharacterEncoding("UTF-8");
		    PrintWriter print=resp.getWriter();  
		       
	        String jsonData=req.getParameter("jsonData");
	        String PostCode=req.getParameter("PostCode");
	        
	        int postCode=Integer.parseInt(PostCode);
	        System.out.println("there is requst in CustomerServlet  "+PostCode+"   "+jsonData);
	        switch(postCode){
	        case 1:  {  // 登陆
	        	 JSONObject temp=  CustomerManagement.loginCheck(jsonData);
	 	          print.println( temp.toString()); 
	 	          System.out.println("data back to app----"+temp);
	    	          break;} 
       
			  case 2:  {  //搜索机器
     	      JSONObject temp=  SearchMachine.search(jsonData);
 	          print.println( temp.toString()); 
 	          System.out.println("data back to app----"+temp);
 	          break;} 
			 
			  case 3:  {  //根据机器获取供应商
	     	      JSONObject temp=  PullSuppliers.pull(jsonData);
	 	          print.println( temp.toString()); 
	 	          System.out.println("data back to app----"+temp);
	 	          break;} 
			  case 4:  {  //根据店铺，拉取分类和产品
	     	      JSONObject temp= PullIndexesAndProducts.pull(jsonData);
	 	          print.println( temp.toString()); 
	 	          System.out.println("data back to app----"+temp);
	 	          break;} 
			  case 5:  {  //获取验证码
	     	      JSONObject temp= TelnumVerifyManagement.manage(jsonData);
	 	          print.println( temp.toString()); 
	 	          System.out.println("data back to app----"+temp);
	 	          break;} 
			  case 6:  {  //账号整改查
	     	      JSONObject temp= CustomerManagement.manage(jsonData);
	 	          print.println( temp.toString()); 
	 	          System.out.println("data back to app----"+temp);
	 	          break;} 
			  
     }
	        
	        print.close();  
	 
	}

	
	
}
